package com.ncloud.crm.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ncloud.common.enmus.ResultEnum;
import com.ncloud.common.exception.UserException;
import com.ncloud.crm.entity.order.OrderDiscntFee;
import com.ncloud.crm.mapper.OrderDiscntFeeMapper;
import com.ncloud.crm.service.OrderDiscntFeeService;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderDiscntFeeServiceImpl implements OrderDiscntFeeService {
	
	private static final Logger logger = LogManager.getLogger(OrderDiscntFeeServiceImpl.class);
	@Autowired
	private OrderDiscntFeeMapper orderDiscntFeeMapper;
	@Override
	public JSONObject getPk(JSONObject json) {
		return null;
	}

	@Override
	public JSONObject insert(JSONObject json) {
		OrderDiscntFee orderDiscntFee = JSON.parseObject(json.toJSONString(),OrderDiscntFee.class);
		try {
			validation(orderDiscntFee);
			orderDiscntFeeMapper.insertOrderDiscntFee(orderDiscntFee);
		}catch (RuntimeException e){
			e.printStackTrace();
			throw new UserException(ResultEnum.DATABASE_ERROR);
		}
		return json;
	}

	@Override
	public JSONObject validate(JSONObject json, JSONObject result) {
		return null;
	}

	private void validation(OrderDiscntFee cust){

	}

	public List<OrderDiscntFee> getByOrderId(Long orderId){
		List<OrderDiscntFee> orderDiscnts = orderDiscntFeeMapper.getDiscntFeeByOrderId(orderId);
		return orderDiscnts;
	}

	@Override
	public OrderDiscntFee getByDiscntInstIdAndOrderId(Long discntInstId, Long orderId) {
		OrderDiscntFee discntFee = orderDiscntFeeMapper.getByDiscntInstIdAndOrderId(discntInstId,orderId);
		return discntFee;
	}
}
